// pagesEnterprise/pages/searchEnterprise/searchEnterprise.js
import ajax from "../../../utils/index"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    dataList: [],
    entity: [],
    formData: {
      phone: '',
      pageSize: 10,
      pageNum: 1,
      total: 0,
    }
  },
  partyNameEvent(event) {
    const entity = event.currentTarget.dataset.item
    const eventChannel = this.getOpenerEventChannel()
    eventChannel.emit('backEvent', entity);
    wx.navigateBack()
  },
  inputChange(event) {
    this.data.formData.phone = event.detail.value
  },
  inputConfirm() {
    const phone = this.data.formData.phone,regExp = ajax.regExp.phone
    if (!phone) return ajax.showToast('请输入手机号码')
    if (!regExp.test(phone)) return ajax.showToast('请输入正确的手机号码')
    this.data.formData.pageNum = 1;
    this.getRequestList()
  },
  async getRequestList() {
    let { dataList, formData } = this.data
    const res = await ajax.get('/wx/contract/partyList', formData).finally(() => wx.stopPullDownRefresh());
    dataList = res.rows
    this.setData({ dataList })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({ 'formData.gardenId': options.gardenId || null })
    this.getRequestList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },
  /**
    * 页面相关事件处理函数--监听用户下拉动作
    */
  onPullDownRefresh: function () {
    this.data.formData.pageNum = 1;
    this.getRequestList()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    const { formData, dataList } = this.data
    if (formData.total == dataList.length) return
    this.data.formData.pageNum += 1;
    this.getRequestList()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})